package com.winbomb.simulife;

import java.util.ArrayList;
import java.util.List;

import com.winbomb.simulife.Identity.IdentityType;
import com.winbomb.simulife.base.IJob;
import com.winbomb.simulife.util.NDRandomGen;
import com.winbomb.simulife.util.RandomGen;

public class Master {

	/** 姓名 */
	String name;

	/** 是否健在 */
	boolean isAlive;

	/** 年龄（年） */
	int ageYear;

	/** 年龄（月） */
	int ageMonth;

	/** 身高 （单位：0.1mm） */
	int height;

	/** 体重（单位：克） */
	int weight;

	/** 游戏中金钱的得分 */
	long moneyScore;

	/** 游戏中快乐的得分 */
	int happyScore;

	/** 游戏中成就的得分 */
	int achievScore;

	/** 心情 **/
	MoodType mood;

	/** 运势 **/
	LuckType luck;

	/** 精力 **/
	int energy;

	/** 压力 **/
	int stress;

	/** 职业 **/
	IJob job;

	/** 工作经验 */
	int workExp;

	/** 能力 */
	Ability ability;

	/** 性格 */
	// Personality personality;

	/** 身份 */
	Identity identity;

	/** 相貌 **/
	LookingType looking;

	/** 婚姻状况 */
	MarritalStatus marrital;

	/** 女朋友，或者是老婆 */
	Girl girl;

	/** 家境情况 */
	Family family;

	/** 财产 */
	List<Asset> assets;

	/** 疾病 */
	List<Disease> diseases;

	/** 所获得的荣誉 */
	Honor honors;

	public Master(String name) {
		this.name = name;
		this.isAlive = true;
		this.ageYear = 0;
		this.ageMonth = 1;
		this.moneyScore = 0;
		this.happyScore = 0;
		this.achievScore = 0;
		this.mood = MoodType.NORMAL;
		this.luck = LuckType.NORMAL;
		this.marrital = MarritalStatus.SINGLE;
		this.family = new Family();
		this.energy = 100;
		this.stress = 0;
		this.identity = new Identity(IdentityType.PUPIL);
		this.job = null;
		this.workExp = 0;
		this.assets = new ArrayList<Asset>();
		this.diseases = new ArrayList<Disease>();
		this.honors = new Honor();

		//
		this.height = 500000; // 50cm
		this.weight = RandomGen.gen(100, 150);

		// 初始化能力
		initAbility();
	}

	private void initAbility() {
		this.ability = new Ability();

		ability.set(Ability.IQ, NDRandomGen.gen(100, 20));
		ability.set(Ability.KNOWLEDGE, 0);
		ability.set(Ability.SPORTS, NDRandomGen.gen(100, 20));
		ability.set(Ability.SINGING, NDRandomGen.gen(100, 20));
		ability.set(Ability.ACTING, NDRandomGen.gen(100, 20));
		ability.set(Ability.ART, NDRandomGen.gen(100, 20));
		ability.set(Ability.POLITICAL, NDRandomGen.gen(100, 20));
	}

	public boolean isAlive() {
		return isAlive;
	}

	public void grow() {

		// 增加年龄
		ageMonth++;
		if (ageMonth >= 13) {
			ageYear++;
			ageMonth = 1;
		}

		// 增加身高
		if (ageYear < 24) {
			height += 0.1;
		}

		// 增加体重
	}

	/**
	 * 成长发育
	 * 
	 * @param growHt
	 *            增加的身高
	 * @param growWt
	 *            增加的体重
	 */
	public void grow(int growHt, int growWt) {
		if (ageYear < 18) {
			height += growHt;
		}

		weight += growWt;

		// 增加年龄
		ageMonth++;
		if (ageMonth % 12 == 0) {
			ageMonth = 0;
			ageYear++;
		}
	}

	/**
	 * 修改某项能力的值
	 * 
	 * @param key
	 *            能力的Key
	 * @param delta
	 *            差值，若为正，则为增加，为负，则为减少
	 */
	public void modifyAbility(String key, int delta) {
		ability.modify(key, delta);
	}

	public void moreHappy() {
		mood = mood.moreHappy();
	}

	public void moreSad() {
		mood = mood.moreSad();
	}

	public int getWeight() {
		return weight;
	}

	public String getName() {
		return name;
	}

	public int getAgeYear() {
		return ageYear;
	}

	public int getAgeMonth() {
		return ageMonth;
	}

	public IJob getJob() {
		return job;
	}

	public int getHeight() {
		return height;
	}

	public MoodType getMoodType() {
		return mood;
	}

	public LuckType getLuckType() {
		return luck;
	}

	public MarritalStatus getMarritalStatus() {
		return marrital;
	}

	public int getAbility(String key) {
		return ability.get(key);
	}

	public boolean hasHonor(HonorType honor) {
		return honors.hasHonor(honor);
	}

	public void addHonor(HonorType honor) {
		honors.addHonor(honor);
	}

	public Identity getIdentity() {
		return identity;
	}

	public Family getFamily() {
		return family;
	}

	public void addAcheivment(int point) {
		achievScore += point;
	}

	public long getMoneyScore() {
		return moneyScore;
	}

	public int getHappyScore() {
		return happyScore;
	}

	public int getAchievScore() {
		return achievScore;
	}

	public int getWorkExperience() {
		return workExp;
	}

	public void setJob(IJob job) {
		this.job = job;
	}

	public Girl getGirl() {
		return girl;
	}

	public void setGirl(Girl girl) {
		this.girl = girl;
	}
}
